# -*- coding: UTF-8 -*-

from sys import argv

"""
    螺旋数
"""


def main():
    """

    :return:
    if len(argv) < 2:
        print("argv's len is less 1.")
        return
    num = int(argv[1])  #
    """
    num = 5
    array = [[0 for i in range(num)] for j in range(num)]
    print(array)
    value = 1  # 数值
    i = 0  # 行
    j = 0  # 列
    direction_i = 0  # 方向
    direction_j = 1
    while(value <= num * num):
        print(i, j, value)
        array[i][j] = value

        if value <= 4 * (num-1):  # 周边
            if j == num-1:  # 右转下
                direction_i = 1
                direction_j = 0

            if i == num-1:  # 下转左
                direction_i = 0
                direction_j = -1

            if j < 1 and value > 3 * (num-1):  # 左转上
                direction_i = -1
                direction_j = 0

            if i <= 1 and value == 4 * (num-1):  # 上转右
                direction_i = 0
                direction_j = 1
        else:
            if direction_i == 0 and direction_j == 1 and array[i + direction_i][j + direction_j] > 0:  # 右转下
                direction_i = 1
                direction_j = 0
            if direction_i == 1 and direction_j == 0 and array[i + direction_i][j + direction_j] > 0:  # 下转左
                direction_i = 0
                direction_j = -1
            if direction_i == 0 and direction_j == -1 and array[i + direction_i][j + direction_j] > 0:  # 左转上
                direction_i = -1
                direction_j = 0
            if direction_i == -1 and direction_j == 0 and array[i + direction_i][j + direction_j] > 0:  # 上转右
                direction_i = 0
                direction_j = 1

        value = value + 1
        i = i + direction_i
        j = j + direction_j


if __name__ == '__main__':
    main()
